import csv
from django.shortcuts import render_to_response
from django.http import HttpResponse
import datetime

def current_datetime(request):
    current_date = datetime.datetime.now()
    return render_to_response('current_date.html',locals())

def hours_ahead(request,offset):
    offset = int(offset) 
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset) 
    return render_to_response('hours_ahead.html',locals())
    
def my_image(request):
    image_data = open("c:/django/test/mysite/Firefox_wallpaper.png","rb").read()
    return HttpResponse(image_data, mimetype="image/png")
    
UNRULY_PASSENGERS = ['aa,a',184,235,200,226,251,299,273,281,304,203]

def unruly_passengers_csv(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=unruly.csv'

    # Create the CSV writer using the HttpResponse as the "file"
    writer = csv.writer(response)
    writer.writerow(['Year', 'Unruly Airline Passengers'])
    for (year, num) in zip(range(1995, 2006), UNRULY_PASSENGERS):
        writer.writerow([year, num])

    return response
